<template>
  <div class="lb-color-list" v-if="colorList.length > 0">
    <top-nav />
    <div class="page-main">
      <div class="flex-warp">
        <div class="mt-md" style="width: 100px">当前配色方案：</div>
        <div class="flex-1">
          <div class="flex-warp">
            <div v-for="(item, index) in colorList" :key="index">
              <div
                @click="changeIndex(index)"
                class="color-item"
                :class="[{ active: index === colorInd }]"
                v-if="index < colorLen - 1"
              >
                <div class="flex-center">
                  <div
                    class="primaryColor"
                    :style="{ background: item.primaryColor }"
                  ></div>
                  <div
                    class="subColor"
                    :style="{ background: item.subColor }"
                  ></div>
                </div>
                <i
                  class="iconfont icon-xuanze-fill flex-center"
                  v-if="index === colorInd"
                ></i>
              </div>
            </div>
            <div
              @click="changeIndex(colorLen - 1)"
              class="color-item"
              :class="[{ active: colorInd === colorLen - 1 }]"
              style="width: auto; padding: 0 2px"
            >
              <div class="flex-center" style="margin-top: 4px">
                <el-color-picker
                  size="medium"
                  style="margin-right: 4px"
                  v-model="colorList[colorLen - 1].primaryColor"
                ></el-color-picker>
                <el-color-picker
                  size="medium"
                  v-model="colorList[colorLen - 1].subColor"
                ></el-color-picker>
              </div>
              <div class="flex-y-center" style="height: 18px; margin-top: 4px">
                <div style="line-height: 18px; font-size: 10px">自定义配色</div>
                <i
                  class="iconfont icon-xuanze flex-center"
                  :class="[
                    {
                      'icon-xuanze-fill': colorInd === colorLen - 1
                    }
                  ]"
                  style="margin: 0"
                ></i>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="space-lg"></div>
      <div class="space-lg"></div>
      <div class="space-lg"></div>
      <div class="flex-warp">
        <div style="width: 100px">当前风格示例：</div>
        <div class="flex-1" style="width: calc(100% - 100px)">
          <div class="c-warning pb-lg">
            当前仅为配色方案演示效果，页面布局以实际为准
          </div>
          <div class="flex-y-center" style="width: 1280px">
            <div class="color-page fill-body rel">
              <img class="navbar-img abs" :src="navbar" />
              <div
                class="navbar-title"
                :style="{ background: colorList[colorInd].primaryColor }"
              >
                <div class="flex-center c-base">首页</div>
              </div>

              <div class="page-content">
                <!-- 服务轮播图 -->
                <service-banner
                  :primaryColor="colorList[colorInd].primaryColor"
                ></service-banner>
                <!-- 分类图 -->
                <service-column :o="columnList"></service-column>
                <!-- 服务列表 -->
                <service-list
                  :primaryColor="colorList[colorInd].primaryColor"
                ></service-list>
                <div class="space-lg"></div>
              </div>
              <tab-bar
                :tabBar="tabBar"
                :nowPageKey="1"
                :selectedColor="colorList[colorInd].primaryColor"
              ></tab-bar>
            </div>
            <!-- 技 师 -->
            <div class="color-page fill-body ml-lg mr-lg rel">
              <img class="navbar-img abs" :src="navbar" />
              <div
                class="navbar-title"
                :style="{ background: colorList[colorInd].primaryColor }"
              >
                <div class="flex-center f-desc c-base">
                  <i
                    class="iconfont iconjuli ml-md mr-sm"
                    style="font-size: 20px"
                  ></i>
                  <div class="max-300 ellipsis">四川省成都市武侯区环球东路</div>
                  <i
                    class="iconfont icon-down"
                    style="transform: scale(0.5)"
                  ></i>
                  <div class="flex-1"></div>
                </div>
              </div>

              <div class="fix-info fill-body rel">
                <div
                  class="space-top abs"
                  :style="{ background: colorList[colorInd].primaryColor }"
                ></div>
                <div class="abs" style="width: 100%; top: 0">
                  <div class="search-info fill-base pt-lg pl-lg pr-lg pb-md">
                    <div class="flex-center">
                      <div class="city-info flex-y-center c-title">
                        成都<i class="iconfont iconshaixuanxia-1 ml-sm"></i>
                      </div>
                      <div class="search-item flex-1 fill-body radius">
                        <i class="iconfont iconsousuo1 mr-sm"></i>请输入{{
                          $t('action.attendantName')
                        }}姓名
                      </div>
                    </div>
                    <div class="order-tablist flex-warp fill-base">
                      <div
                        class="tablist-item flex-center rel"
                        v-for="(item, index) in technicianTabList"
                        :key="index"
                        :style="{
                          width: 100 / technicianTabList.length + '%',
                          color:
                            index === 0
                              ? colorList[colorInd].primaryColor
                              : '#333'
                        }"
                      >
                        {{ item.title }}
                        <div
                          class="line abs"
                          :style="{
                            background: colorList[colorInd].primaryColor
                          }"
                          v-if="index === 0"
                        ></div>
                      </div>
                    </div>
                  </div>
                  <div class="search-cate-list flex-warp mt-md">
                    <div class="item-child flex-center">
                      <div class="ellipsis">
                        推荐{{ $t('action.attendantName') }}
                      </div>
                    </div>
                    <div class="item-child flex-center">按摩预约</div>
                    <div class="item-child flex-center">推拿预约</div>
                    <div class="item-child flex-center">更多筛选</div>
                  </div>
                </div>
              </div>

              <div class="page-content coach">
                <!-- 技-师列表 -->
                <coach-list
                  :primaryColor="colorList[colorInd].primaryColor"
                  :sbcolor="service_btn_color"
                  :sfcolor="service_font_color"
                ></coach-list>
                <div class="space-lg"></div>
              </div>

              <tab-bar
                :tabBar="tabBar"
                :nowPageKey="2"
                :selectedColor="colorList[colorInd].primaryColor"
              ></tab-bar>
            </div>
            <!-- 订单 -->
            <div class="color-page fill-body rel">
              <img class="navbar-img abs" :src="navbar" />
              <div
                class="navbar-title"
                :style="{ background: colorList[colorInd].primaryColor }"
              >
                <div class="flex-center c-base">订单</div>
              </div>
              <div class="order-tablist flex-warp fill-base">
                <div
                  class="tablist-item flex-center rel"
                  v-for="(item, index) in orderTabList"
                  :key="index"
                  :style="{
                    width: 100 / orderTabList.length + '%',
                    color:
                      index === 0 ? colorList[colorInd].primaryColor : '#333'
                  }"
                >
                  {{ item.title }}
                  <div
                    class="line abs"
                    :style="{ background: colorList[colorInd].primaryColor }"
                    v-if="index === 0"
                  ></div>
                </div>
              </div>

              <div class="page-content order">
                <!-- 订单列表 -->
                <order-list
                  :primaryColor="colorList[colorInd].primaryColor"
                ></order-list>
                <div class="space-lg"></div>
              </div>

              <tab-bar
                :tabBar="tabBar"
                :nowPageKey="4"
                :selectedColor="colorList[colorInd].primaryColor"
              ></tab-bar>
            </div>
          </div>
        </div>
      </div>
      <div class="space-lg"></div>
    </div>

    <div class="flex-center pd-lg b-1px-t">
      <el-button
        class="mr-md"
        type="danger"
        :plain="true"
        @click="getSystemDefaulDiy"
        >{{ $t('action.defaultSet') }}</el-button
      >
      <el-button type="primary" @click="submitFormInfo" v-preventReClick
        >保存</el-button
      >
    </div>
  </div>
</template>

<script>
import tabBar from '@/components/diy/tabBar.vue'
import serviceColumn from '@/components/diy/serviceColumn.vue'
import serviceBanner from '@/components/diy/serviceBanner.vue'
import serviceList from '@/components/diy/serviceList.vue'
import coachList from '@/components/diy/coachList.vue'
import orderList from '@/components/diy/orderList.vue'
export default {
  components: {
    tabBar,
    serviceColumn,
    serviceBanner,
    serviceList,
    coachList,
    orderList
  },
  data () {
    return {
      navbar: 'https://lbqny.migugu.com/admin/diy/navbar_white_none.png',
      banner:
        'https://lbqnyv3.migugu.com/image/666/23/05/coLq1uUiDPgsYSUJrcX6qQfMGt87Cg7K.jpg',
      colorList: [{
        primaryColor: '#A40035',
        subColor: '#F1C06B'
      }, {
        primaryColor: '#19c865',
        subColor: '#f86c53'
      }, {
        primaryColor: '#db4d4d',
        subColor: '#e28e5f'
      }, {
        primaryColor: '#dd6630',
        subColor: '#e39a32'
      }, {
        primaryColor: '#ebcc3b',
        subColor: '#20252d'
      }, {
        primaryColor: '#8ac4aa',
        subColor: '#232826'
      }, {
        primaryColor: '#8228f9',
        subColor: '#b49fe2'
      }, {
        primaryColor: '#ca2432',
        subColor: '#efd645'
      }, {
        primaryColor: '#db4d4d',
        subColor: '#555555'
      }, {
        primaryColor: '#85c077',
        subColor: '#b1dda7'
      }, {
        primaryColor: '#baaa6f',
        subColor: '#dcd5a9'
      }],
      primaryColor: '#A40035',
      subColor: '#F1C06B',
      colorInd: 0,
      colorLen: 0,
      tabBar: [],
      technicianTabList: [{
        title: '全部',
        id: 0
      }, {
        title: '可服务',
        id: 1
      }, {
        title: '服务中',
        id: 5
      }, {
        title: '可预约',
        id: 5
      }],
      orderTabList: [{
        title: '全部',
        id: 0
      }, {
        title: '待支付',
        id: 1
      }, {
        title: '待服务',
        id: 5
      }, {
        title: '服务中',
        id: 6
      }, {
        title: '已完成',
        id: 7
      }],
      service_btn_color: '',
      service_font_color: ''
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    async changeIndex (index) {
      this.colorInd = index
    },
    async getFormInfo () {
      let [configinfo, diyinfo] = await Promise.all([this.$api.system.configInfo(), this.$api.diy.diyInfo()])
      let { tabbar } = diyinfo.data
      this.tabBar = tabbar
      let { primaryColor, subColor, service_btn_color: sbtn, service_font_color: sfont } = configinfo.data
      sbtn = !sbtn ? '#282B34' : sbtn
      sfont = !sfont ? '#EBDDB1' : sfont
      this.service_btn_color = sbtn
      this.service_font_color = sfont
      let colorList = JSON.parse(JSON.stringify(this.colorList))
      let arr = colorList.filter(item => {
        return item.primaryColor === primaryColor && item.subColor === subColor
      })
      if (arr.length === 0) {
        colorList.push({
          primaryColor,
          subColor
        })
      } else {
        colorList.push({
          primaryColor: '',
          subColor: ''
        })
      }
      this.colorList = colorList
      this.colorLen = colorList.length
      let ind = -1
      colorList.map((item, index) => {
        if (item.primaryColor === primaryColor && item.subColor === subColor) {
          ind = index
        }
      })
      this.colorInd = ind === -1 ? colorList.length - 1 : ind
    },
    async getSystemDefaulDiy () {
      this.colorInd = 0
      await this.submitFormInfo()
    },
    async submitFormInfo () {
      let { primaryColor, subColor } = this.colorList[this.colorInd]
      if (!primaryColor || !subColor) {
        this.$message.error(!primaryColor ? `请选择主色` : `请选择辅色`)
        return
      }
      let { code } = await this.$api.system.configUpdate({ primaryColor, subColor })
      if (code !== 200) return
      this.$message.success(this.$t('tips.successSave'))
    }
  }
}
</script>

<style lang="scss" scoped>
.color-item {
  width: 84px;
  height: 68px;
  margin: 10px 10px 0 0;
  padding-top: 2px;
  border: 1px solid white;
  cursor: pointer;
  .iconfont {
    color: #429dff;
    margin-top: 5px;
  }
}
.color-item.active {
  border: 1px solid #429dff;
  border-radius: 5px;
  box-shadow: 0px 4px 12px 1px rgba(66, 157, 255, 0.15);
}
.primaryColor,
.subColor {
  width: 40px;
  height: 40px;
  border-radius: 5px 0 0 5px;
}
.subColor {
  border-radius: 0 5px 5px 0;
}
.color-page {
  width: 375px;
  height: 660px;
  overflow: hidden;
  border-radius: 5px;
  border: 1px solid #eee;
  .navbar-img {
    width: 375px;
    height: 65px;
  }
  .navbar-title {
    width: 375px;
    height: 65px;
    .flex-center {
      height: 65px;
      padding-top: 18px;
    }
  }

  .page-content {
    width: 373px;
    height: calc(100% - 65px - 56px);
    overflow: auto;
  }
  .page-content.coach {
    height: calc(100% - 65px - 148px - 56px);
  }
  .page-content.order {
    height: calc(100% - 65px - 50px - 56px);
  }
  // 技-师
  .fix-info {
    height: 148px;

    .space-top {
      width: 100%;
      height: 20px;
      top: 0;
    }

    .search-info {
      width: 100%;
      top: 0;
      border-radius: 20px;
      font-size: 13px;

      .city-info {
        width: 65px;

        .iconfont {
          font-size: 10px;
          transform: scale(0.4);
        }
      }
      .search-item {
        height: 32px;
        padding: 0 15px;
        line-height: 32px;
        .iconfont {
          font-size: 14px;
        }
      }
    }
    .search-cate-list {
      margin: 10px 8px;
      .item-child {
        width: 80px;
        height: 30px;
        padding: 0 5px;
        color: #484848;
        margin-left: 12px;
        background: #ffffff;
        font-size: 12px;
        border-radius: 6px;
      }
      .item-child:nth-child(1) {
        margin-left: 0;
      }
    }
  }
  // 订单
  .order-tablist {
    width: 100%;
    height: 50px;
    .tablist-item {
      .line {
        width: 40px;
        height: 3px;
        border-radius: 3px;
        left: 50%;
        bottom: 0;
        margin-left: -20px;
      }
    }
  }
}
</style>
